import re

from django import http
from django.contrib.auth import login, authenticate
from django.shortcuts import render, redirect

# Create your views here.
from django.views import View
from requests import Response
from rest_framework import status
from rest_framework.views import APIView

from Good_house.Good_house.apps.users.models import User
from Good_house.Good_house.apps.users.serializers import AdminAuthSerializer


class LoginView(APIView):
    def post(self, request):
        """
        登录:
        1. 获取参数并进行校验
        2. 服务器签发jwt token数据
        3. 返回应答
        """
        # 1. 获取参数并进行校验
        serializer = AdminAuthSerializer(data=request.data)
        serializer.is_valid(raise_exception=True)

        # 2. 服务器签发jwt token数据(create)
        serializer.save()

        # 3. 返回应答
        return Response(serializer.data, status=status.HTTP_201_CREATED)




